package gui.cen.tree;

import gui.utils.Borders;
import gui.utils.Para;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class ScaleBarPanel extends JPanel implements ActionListener{ 
    private JTextField text;
    private TreeDisp td;
    public ScaleBarPanel(TreeDisp td){
        super(new GridLayout(1, 2));
        this.td = td;
        JLabel label = new JLabel("Scale ");
        label.setFont(Borders.getFont(Borders.GUIFONT));
        label.setHorizontalAlignment(SwingConstants.RIGHT);
        this.add(label);

        JPanel p1 = new JPanel();
        p1.setLayout(new BorderLayout());
        p1.setBorder(BorderFactory.createEmptyBorder(9,0,9,0));

        text = new JTextField();
        text.setFont(Borders.getFont(Borders.GUIFONT));
        text.addActionListener(this);
        p1.add(text, BorderLayout.CENTER);

        this.add(p1, BorderLayout.CENTER);
    } 

    public void actionPerformed(ActionEvent evt){
        Object source = evt.getSource(); 
        if(source == text && Para.TREE!=null){
            try{td.getTreePane().setScale(new Double(text.getText()).doubleValue());}
            catch(Exception e){td.getTreePane().setScale(0.00);}
            td.getTreePane().repaint();
        }
        else{td.msg("No Tree Available");}
    }
}

